home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / NTUMIN10.ARJ / ADJACENC.C < prev    next >
C/C++ Source or Header  |  1992-03-12  |  3KB  |  91 lines

  1. /****************************************************************************
  2.  *
  3.  *    Program Name : ADJACENC.C
  4.  *
  5.  *    Written By : Eng-Huat Ong and Kian-Mong Low.
  6.  *
  7.  *    This program generate the possible adjacent terms given the minterm.
  8.  *     It then computes the adjacency of the minterm base on the possible
  9.  *    adjacent terms generated.
  10.  *
  11.  *    Returns adjacency of the given minterm.
  12.  *
  13.  * --------------------------------------------------------------------------
  14.  *    Copyright (c) 1992. All Rights Reserved. Nanyang Technological
  15.  *    University.
  16.  *
  17.  *    You are free to use, copy and distribute this software and its
  18.  *    documentation providing that:
  19.  *
  20.  *        NO FEE IS CHARGED FOR USE, COPYING OR DISTRIBUTION.
  21.  *
  22.  *        IT IS NOT MODIFIED IN ANY WAY.
  23.  *
  24.  *        THE COPYRIGHT NOTICE APPEAR IN ALL COPIES.
  25.  *
  26.  *    This program is provided "AS IS" without any warranty, expressed or
  27.  *    implied, including but not limited to fitness for any particular
  28.  *    purpose.
  29.  *
  30.  *    If you find NTUMIN fast, easy, and useful, a note or comment would be
  31.  *    appreciated. Please send to:
  32.  *
  33.  *        Boon-Tiong Tan or Othman Bin Ahmad
  34.  *        School of EEE
  35.  *        Nanyang Technological University
  36.  *        Nanyang Avenue
  37.  *        Singapore 2263
  38.  *        Republic of Singapore
  39.  *
  40.  ***************************************************************************/
  41.  
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44.  
  45. unsigned char   adjacency(temp, a)
  46. unsigned char     *a, *temp;
  47.  
  48.  
  49. {
  50.    unsigned short  m;
  51.    unsigned char   *adjterm;
  52.    unsigned char   i, j, nspm, n, adj;
  53.    char            test;
  54.  
  55.  
  56.    n    = *a;                              /* no. if variables */
  57.    nspm = *(a+3);                          /* no. of bytes/minterm */
  58.    m  = *(a+2)<<8 | *(a+1);                /* no. of minterms */
  59.  
  60.    adjterm = (unsigned char *)  malloc(nspm+1);  /* temporary storage */
  61.    if (adjterm == 0)
  62.       {
  63.      printf("Out of memory -- ADJACENC, *adjterm\n");
  64.      printf("Program Terminated - 1\n");
  65.      exit(0);
  66.       }
  67.  
  68.    adj = 0;
  69.  
  70.    for (i=0; i<n; i++)
  71.       {
  72.      for (j=0; j<nspm; j++)        /* generate possible adjacent terms */
  73.         {
  74.            if ((i/8) == j)
  75.           *(adjterm+j) = *(temp+j) ^ (1<<(i%8));   /* XOR */
  76.            else
  77.           *(adjterm+j) = *(temp+j);
  78.         }
  79.  
  80.      test = exist(adjterm, a, m);
  81.      if (test == 0)                      /* exist in a-array */
  82.         adj++;
  83.       }
  84.  
  85.    free(adjterm);                            /* free pointer */
  86.  
  87.    return(adj);                              /* return adjacency */
  88. }
  89.  
  90.  
  91.